#include "vl_prop_writer.h"
#include <cstdarg>
#include <cstring>

using namespace VL;


VLPropWriter::~VLPropWriter() {}

void VLPropWriter::writeStr(const char * fmt, ...) {
	va_list va;
	va_start(va, fmt);
	va_list copyList;
	va_copy(copyList, va);
	auto strSize = vsnprintf(nullptr, 0, fmt, copyList);
	va_end(copyList);
	char buffer[strSize + 1];
	vsnprintf(buffer, strSize + 1, fmt, va);
	va_end(va);
	buffer[strSize] = '\0';
	this->writeBuf((const uint8_t *) buffer, strSize);
}

void VLPropWriter::writeStrWithSize(const std::string& str) {
	auto size = str.size();
	this->write(size, 4);
	this->writeBuf((const uint8_t *) str.c_str(), size);
}